<?php 
/*------------------------------------------------------------------------
# resumes - company resumes management 
# @author    pipapai.com
-------------------------------------------------------------------------*/

defined('_JEXEC') or die;
// disable core styles to avoid bs conflict 
OC_Util::$core_styles = array();

if(isDevMode()) {
   OCP\Util::addStyle('company', 'company');
   OCP\Util::addStyle('resumes', 'resumes');
   OCP\Util::addStyle('resumes', 'share');
   OCP\Util::addStyle('calendar', 'calendar.common');
   OCP\Util::addScript('resumes', 'share');

   // Load the files we need
   OCP\Util::addScript('resumes', 'resumes');
   OCP\Util::addScript('resumes', 'resumelist');
   OCP\Util::addScript('resumes', 'foldermanage');
   OCP\Util::addScript('resumes', 'resumeactions');
   OCP\Util::addScript('resumes', 'keyboardshortcuts');
   OCP\Util::addScript('resumes', 'resumes.common');
} else {
   OCP\Util::addStyle('static', 'resumes');
   OCP\Util::addScript('static', 'apps/resumes.min');
}

$dir = JRequest::getString('dir', 'all');

$isMasterUser = PFactory::isMasterUser();
$isJobManagerViewOnly = PCompanyHelper::isJobManagerViewOnly();
$isSearching = PResumesHelper::isSearching();

OCP\App::setActiveNavigationEntry('resumes_index');
// Load the resumes
?>

<?php if(isDevMode()): ?>
<script type="text/javascript" src="<?=OC_Helper::linkTo("", "themes/jobs/core/js/jquery/rgraph/RGraph.common.core.js")?>"></script>
<script type="text/javascript" src="<?=OC_Helper::linkTo("", "themes/jobs/core/js/jquery/rgraph/RGraph.common.dynamic.js")?>"></script>
<script type="text/javascript" src="<?=OC_Helper::linkTo("", "themes/jobs/core/js/jquery/rgraph/RGraph.common.tooltips.js")?>"></script>
<script type="text/javascript" src="<?=OC_Helper::linkTo("", "themes/jobs/core/js/jquery/rgraph/RGraph.common.effects.js")?>"></script>
<script type="text/javascript" src="<?=OC_Helper::linkTo("", "themes/jobs/core/js/jquery/rgraph/RGraph.radar.js")?>"></script>
<?php endif; ?>  
<!--[if IE]>
<?php if(isDevMode()): ?>
   <script type="text/javascript" src="<?php echo OC_Helper::linkTo("", "themes/jobs/core/js/jquery/jqplot/excanvas.js"); ?>"></script>
<?php else:?>
   <?php PUtil::loadJs("static/js/jquery/plugin/jqplot.excanvas.min.js"); ?>
<?php endif; ?>
<![endif]-->

<script type="text/javascript" src="<?php print_unescaped(OC_Helper::linkTo('resumes/js', 'resumes.php'));?>"></script>
<div id="controls" class="hr_inner_navigate clearfix" style="box-shadow:none;">
      <div class="actions clearfix <?php if (isset($_['resumes']) and count($_['resumes'])==0):?>emptyfolder<?php endif; ?>">
         <ul>
            <li class="<?php echo $dir == "all" ? "cur_li" : ""; ?>">
               <a href="<?php echo OC_Helper::linkToRoute('resumes_folder');?>"><?=($isMasterUser ? '全部简历' : '我的简历')?></a>
            </li>
            <li class="<?php echo $dir == "saved" ? "cur_li" : ""; ?>">
               <a href="<?php echo OC_Helper::linkToRoute('resumes_folder', array('dir' => 'saved'));?>">我的收藏</a>
            </li>
            
            <?php 
            $moreselected = true;
            $moreFolderName = '';
            $noDataTips = '您的云简历库是空的';
            switch ($dir) {
               case 'all':
                  $moreselected = false;
                  if ($isMasterUser) {
                     $noDataTips = '您的云简历库是空的';
                  } else {
                     $noDataTips = '您管理的云简历库是空的';
                  }
                  break;
               case 'saved':
                  $moreselected = false;
                  $noDataTips = '您的收藏简历库是空的';
                  break;
               case 'shared':
                  $moreFolderName = '收到的分享';
                  $noDataTips = '您的分享简历库是空的';
                  break;
               case 'trashed':
                  $moreFolderName = '回收站';
                  $noDataTips = '您的回收站是空的';
                  break;
               case 'company':
                  $moreFolderName = '公司人才夹';
                  $noDataTips = '您的公司简历库是空的';
                  break;
               default:
                  if (is_numeric($dir)) {
                     $dirInfo = PResumesHelper::getDirInfo($dir);
                     if (empty($dirInfo)) {
                        $foldername = JRequest::getString('foldername', null);
                        $moreFolderName = $foldername ? $foldername : '';
                        $noDataTips = '当前文件夹不存在';
                     } else {
                        $moreFolderName = $dirInfo['foldername'];
                        $noDataTips = "您的{$moreFolderName}文件夹是空的";
                     }
                  } else {
                     $noDataTips = '当前文件夹不存在';
                  }                  
                  break;
            }
            ?>
            <li class="dropdown <?php echo $moreselected ? "cur_li" : "";?>" id="more_folder">
               <a href="javascript:;" id="selectmore_folder" class="dropdown-toggle" data-target="#" data-placement="bottom" title="<?php echo compact_strlen($moreFolderName)>11 ? $moreFolderName : '';?>"><b><?=(empty($moreFolderName) ? '文件夹' : strmaxtextlen($moreFolderName, 12))?></b> <i class="blue_triangle"></i></a>
               <div id="folder_dropdown" class="folder_option dropdown-menu popup"></div>
            </li>
         </ul>

         <div class="resume_search pull-left" style="margin-left:-10px;">
            <?php if(PCompanyHelper::isJobAdmin()):?>
            <a class="ppp_bluebtn" id="handleaddresume" href='<?php echo OC_Helper::linkToRoute('resume_showaddform');?>'>手动创建</a>
            <a class="ppp_bluebtn importresumesdbtn" id="batchimportbtn" data-endid="_local" href='<?php echo OC_Helper::linkToRoute('resume_showimportdialog').'?time='.time();?>'>本地上传</a>
            <a class="ppp_bluebtn importresumesdbtn" id="batchimportbtn" data-endid="_offsite" href='<?php echo OC_Helper::linkToRoute('resume_showimportdialog').'?time='.time();?>'>第三方导入</a>
            <?php endif;?>
            
            <?php if(0): ?>
            <a class="ppp_bluebtn" id="offsitesarbtn" href='<?php echo OC_Helper::linkToRoute("resumes_offsitesearch");?>'>云人才搜索</a>
            <?php endif; ?>
         </div>
         
         <?php
            $dirTipsHtml = '';
            if ($dir == 'trashed') {
               $dirTipsHtml = '回收站里的简历将会最多保存30天。';
            }
            
            if (!empty($dirTipsHtml)) {
               echo '<div class="pull-right medium trashedtip" style="">' . $dirTipsHtml . '</div>';
            }
         ?>
         
      </div>
   
   <!-- <input type="hidden" name="dir" value="<?php echo $dir ?>" id="dir">  -->
   <input type="hidden" name="permissions" value="<?php echo $_['permissions']; ?>" id="permissions">
</div>

<div class="resume_search fixed_resume_search clearfix">
   <div class="hr_breadcrumbs pull-left">
      <?php if(isset($_['breadcrumb'])): ?>
         <?php echo($_['breadcrumb']); ?>
      <?php endif; ?>
   </div>

   <div class="positionselect medium pull-left" style="margin-top:4px;">
      <span>职位：</span>
      <?php 
      $jobid = JRequest::getInt('jobid', 0);
      $selectedjob = PResumesHelper::getJob($jobid);
      ?>
      <div class="comselectmenubox dropdown" id="joblinks">
         <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-target="#"><b><?=(empty($selectedjob) ? '全部' : ($selectedjob->job_title=='无职位' ? '--' : $selectedjob->job_title))?></b> <i></i></a>
         <div class="dropdown-menu">
            <?php 
            list($href, $selected) = PResumesHelper::getSearchItemHref($_['searchUrl'], 'jobid', 'all');
            ?>
            <a href="<?=$href?>" <?=($selected ? 'class="cur_a"'  : '')?>>全部</a>
            <?php 
            if (!empty($_['jobList'])) {
               $i=0;
               foreach ($_['jobList'] as $job) {
                  if ($i == 10) {
                     echo '<a href="javascript:;" class="last_lookmore showlist">查看更多...</a>';
                     break;
                  }
                  list($href, $selected) = PResumesHelper::getSearchItemHref($_['searchUrl'], 'jobid', $job['id']);
            ?>
            <a href="<?=$href?>" <?=($selected ? 'class="cur_a"'  : '')?>><?=($job['job_title'] =='无职位' ? '--(无职位)':$job['job_title'])?></a>
            <?php
               $i++;
               }
            }
            ?>
         </div>
      </div>
      <span class="line">|</span>
      <span>标签：</span>
      <?php 
      $tagname = JRequest::getString('tag', null);
      $selectedtag = PResumesHelper::getTag($tagname);
      ?>
      <div class="comselectmenubox dropdown" id="taglinks">
         <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-target="#"><b><?=(empty($selectedtag) ? '全部' : $selectedtag->name) ?></b> <i></i></a>
         <div class="dropdown-menu">
            <?php 
            list($href, $selected) = PResumesHelper::getSearchItemHref($_['searchUrl'], 'tag', 'all');
            ?>
            <a href="<?=$href?>" <?=($selected ? 'class="cur_a"'  : '')?>>全部</a>
            <?php 
            if (!empty($_['tagList'])) {
               $i=0;
               foreach ($_['tagList'] as $tag) {
                  if ($i == 10) {
                     echo '<a href="javascript:;" class="last_lookmore showlist">查看更多...</a>';
                     break;
                  }
                  list($href, $selected) = PResumesHelper::getSearchItemHref($_['searchUrl'], 'tag', $tag['name']);
            ?>
            <a href="<?=$href?>" <?=($selected ? 'class="cur_a"'  : '')?>><?=$tag['name']?></a>
            <?php
               $i++;
               }
            }
            ?>
         </div>
      </div>
   </div>

   <?php if ($dir != 'trashed'): ?>
      <?php if(0): ?><!-- 取消高级筛选展开收起功能 -->
      <div id="advancedSearch" class="highsearch pull-left <?=(isset($_['advancedSearch']) ? 'lowsearch' : '')?>"><a href="javascript:;">高级筛选</a><i></i></div> <!--  lowserarch -->
      <?php endif; ?>
   
   <div class="chooseresumeshow medium pull-left">
      <span>显示：</span>
      <a href="javascript:;" id="showlist" title="列表显示" data-placement="left" class="showways_close <?=(empty($_['showdetail']) ? 'curselect' : '')?>"></a>
      <a href="javascript:;" id="showdetail" title="详情显示" data-placement="right" class="showways_open <?=(!empty($_['showdetail']) ? 'curselect' : '')?>"></a>
      <span class="line">|</span>
      <?php 
      list($href, $selected) = PResumesHelper::getSearchItemHref($_['searchUrl'], 'isnew', 'all');
      ?>
      <a href="<?=$href?>" class="statusselect <?=($selected ? 'statusselect_cur' : '')?>">全部</a>
      <?php
      $isnewConfig = array(
               '0' => '已读',
               '1' => '未读'
      );
      foreach ($isnewConfig as $isnewValue => $isnewName) {
         list($href, $selected) = PResumesHelper::getSearchItemHref($_['searchUrl'], 'isnew', $isnewValue);
      ?>
      <a href="<?=$href?>" class="statusselect <?=($selected ? 'statusselect_cur' : '')?>"><?=$isnewName?></a>
      <?php
      }
      ?>
   </div>
   <?php endif; ?>

</div>

<!-- div class resumesearch_wrap please ajax to load -->
<?php 
$searchData = "{'searchurl': '" . $_['searchUrl'] . 
              "', 'jobpos': '" . $_['jobpos'] . 
              "', 'jobid': '" . JRequest::getInt('jobid', 0) . 
              "', 'tag': '" . JRequest::getString('tag', '') . 
              "', 'dir': '" . $dir .
              "', 'jobsearchurl': '" . (OC_Helper::linkToRoute('resumes_joblist') . '?q=%q') . 
              "', 'tagsearchurl': '" . (OC_Helper::linkToRoute('resumes_taglist') . '?q=%q') . "'}";
?>
<div id="resumesearch_wrap" data="<?=$searchData?>" class="highsearch_wrap" <?=(isset($_['advancedSearch']) ? '' : 'style="display: none;"')?>><?=(isset($_['advancedSearch']) ? $_['advancedSearch'] : '')?></div>

<div class="hr_resume_tablebox">
<?php if ($isSearching || !empty($_['resumes'])): ?>
<?php $folderinfo = $_['folderinfo'];?>
<table class="resume_listtable showshare medium <?=(isset($_['advancedSearch']) ? 'slidedown' : '')?> pipapai" width="100%" border="0" cellpadding="0" cellspacing="0" style="border-collapse:separate;">
   <thead>
      <tr>
         <th align="left" id='headerName' style="padding-left:10px;">
            <input type="checkbox" id="select_all" autocomplete="off" style="margin-right:0px;" />
            <em style="margin-right:20px; font-weight:normal;">全选</em>
            <span class='name'>姓名 / 信息</span>
            <span class="actions_change">
            <?php if($_['allowZipDownload']) : ?>
               <span class='selectedActions'>
                  <a href="" class="download">
                     <i class="download"></i>
                     <?php echo $l->t('Download')?>
                  </a>
               </span>
            <?php endif; ?>
            
            <?php if ($dir != 'saved' && $dir != 'trashed'): ?>
               <span class="selectedActions">
                  <a href="" class="save">
                     <i class="save"></i>
                     <?php echo $l->t('Save')?>
                  </a>
               </span>
               <span class="selectedActions">
                  <a href="" class="unsave">
                     <i class="unsave"></i>
                     <?php echo $l->t('Unsave')?>
                  </a>
               </span>
            <?php endif; ?>
            
            <?php if ($dir == 'saved'): ?>
               <span class="selectedActions">
                  <a href="" class="unsave">
                     <i class="unsave"></i>
                     <?php echo $l->t('Unsave')?>
                  </a>
               </span>
            <?php endif; ?>

            <?php if ($_['permissions'] & OCP\PERMISSION_DELETE): ?>
               <?php if ($dir == 'shared' && 0): ?>
                  <span class="selectedActions">
                     <a href="" class="delete">
                        <i class="delete"></i>
                        <?php echo $l->t('Unshare')?>
                     </a>
                  </span>
               <?php endif; ?>
               <?php if ($dir == 'trashed'): ?>
                  <span class="selectedActions">
                     <a href="" class="restore">
                        <i class="restore"></i>
                        <?php echo $l->t('Restore')?>
                     </a>
                  </span>
                  <span class="selectedActions">
                     <a href="" class="permdelete">
                        <i class="permdelete"></i>
                        <?php echo $l->t('Permdelete')?>
                     </a>
                  </span>
               <?php endif; ?>
               
               <?php if ($dir != 'trashed' && $dir != 'company'): ?>
                  <span class="selectedActions">
                     <a href="" class="delete">
                        <i class="delete"></i>
                        <?php echo $l->t('Delete')?>
                     </a>
                  </span>
                  <span class="selectedActions">
                     <a href="" class="invite">
                        <i class="invite"></i>
                        邀请评测
                     </a>
                  </span>
               <?php else: ?>
               <?php endif; ?>
               
               <?php if ($dir != 'trashed'): ?>
                  <span class="selectedActions">
                     <a href="" class="infolder">
                        <i class="infolder"></i>
                        移入文件夹
                     </a>
                  </span>
               <?php endif; ?>
               
            <?php endif; ?>
            </span>
         </th>
         <th align="left" id="headerResumeStatus">
            <span>状态<i class="down_triangle"></i>
               <?php PResumesHelper::showResumeStatuses($_['resumeStatuses']); ?>
            </span>
         </th>
         <th align="left" id="headerWork"><span><a class='sort <?=($_['topnlist'] ? 'topnlist': '')?>' data-orderby='workexp' data-orderdir='desc' href="javascript:;">工作经验<i class="downblack"></i></a></span></th>
         <th align="left" id="headerDegree"><span><a class='sort <?=($_['topnlist'] ? 'topnlist': '')?>' data-orderby='degree' data-orderdir='desc' href="javascript:;">学历<i class="downblack"></i></a></span></th>
         <th align="left" id="headerPosition" style="display: <?=(empty($jobid) ? '' : 'none')?>"><span>申请职位</span></th>
         <th align="center" id="headerMatch"><span><a class='sort <?=($_['topnlist'] ? 'topnlist': '')?>' data-orderby='matchresult' data-orderdir='desc' href="javascript:;">匹配度<i class="downblack"></i></a></span></th>
         <th align="center" id="headerTest"><span>应聘进度</span></th>
         <th align="center" id="headerDate"><span><a class='sort <?=($_['topnlist'] ? 'topnlist': '')?>' data-orderby='added' data-orderdir='desc' href="javascript:;">
         <?=((!empty($folderinfo) && ($folderinfo->folder_name =='导入文件夹' || $folderinfo->folder_name == '_t'.$folderinfo->delaytaskid )) ? '更新时间':'申请时间')?>
         <i class="downblack"></i></a></span></th>
      </tr>
   </thead>
   <tbody id="resumeList">
      <?php
      // show tips when searching
      if (empty($_['resumes'])) {
         if ($moreselected && empty($moreFolderName)) {
            echo '<tr><td colspan=8>当前文件夹不存在</td></tr>';
         } else {
            echo '<tr><td colspan=8>没有找到符合条件的简历</td></tr>';
         }
      }
      
      if (!empty($_['resumes'])) {
         echo($_['resumeList']);
      }
      ?>
   </tbody>
</table>
<?php endif; ?>
</div>

<?php if (empty($_['resumes']) && !$isSearching): ?>
   <div class="hr_position_nodata">
      <div class="hr_netaddress">
         <span class="nodata_tip yahei large"><?=$noDataTips?></span>
         <?php if($dir == 'all' && $isMasterUser): ?>
            <br/><span class="hr_net_config">完成职位同步后，云招聘会自动同步职位信息并接收简历。</span>
            <a href="<?php echo OC_Helper::linkToRoute("company_synchronousinfo"); ?>" id="" style="display:inline-block;">立即同步</a>
         <?php endif; ?>
      </div>
   </div>
   
   <?php if(($dir =='all') && $isMasterUser): ?>
   <div class="hr_net_tipdialog popup" id="hr_howtoconfig" style="width:260px; display:none; top:auto; left:auto;">
      <div class="hr_net_point"></div>
      <div class="closediv"></div>
   	<div class="hr_net_tipcontent">
   	   <p>1. 登录<a href="http://ehire.51job.com/MainLogin.aspx" target="_blank">前程无忧</a> / <a href="http://hr.zhaopin.com/hrclub/index.html" target="_blank">智联招聘</a> / <a href="http://ent.buildhr.com/login" target="_blank">建筑英才</a></p>
         <p>2. 进入已发布的职位详情页</p>
         <p class="clearfix"><em class="pull-left">3.</em> <em class="blockstyle">找到<b>简历接收方式</b>，填写云招聘邮箱<br/>地址 <b class="yellowcolor"><?=PCompanyHelper::getResumeForwardEmail()?></b></em></p>
         <p class="textright"><a href="<?=JURI::base()?>helps/doc/product/resumeforward_51job.html">查看详细帮助</a></p>
      </div>
   </div>
   <?php endif; ?>
   
<?php else: ?>
<?php endif; ?>

<div id="pagination" class="<?=(isset($_['advancedSearch']) ? 'slidedown' : '')?>" style="padding-top:0px;<?php echo ($_['pagination']->pagesTotal > 1) ? '' : 'display:none;'?>">
   <?php echo $_['pagination']->getListFooter(); ?>
</div>

<div id="scanning-message">
   <h3>
      <?php echo $l->t('Resumes are being loaded, please wait.');?> <span id='scan-count'></span>
   </h3>
   <p>
      <?php echo $l->t('Current loading');?> <span id='scan-current'></span>
   </p>
</div>

<div id="persontest_result" class="modal fade hide" style="position:absolute;">
</div>

<div id="persontest_noresult" class="modal fade hide" style="position:absolute;">
</div>

<div class="modal hide fade foldermanagedialog" style="position:absolute;" id="infolder_modal">
   <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
      <h3>移动简历</h3>
   </div>
   <div class="modal-body" id="infolder_body"></div>
</div>

<div class="modal hide fade foldermanagedialog" style="position:absolute;" id="foldermanage_modal">
   <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
      <h3>文件夹管理</h3>
   </div>
   <div class="modal-body" id="foldermanage_body"></div>
</div>

<div id="creater_newfolder" class="modal fade hide creater_newfolder">
   <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
      <h3>创建文件夹</h3>
   </div>
   <div class="modal-body">
      <form id="newfolderform" action="<?=OC_Helper::linkTo('resumes','ajax/savefolder.php')?>" method="POST" autocomplete="off">
      <div class="form-horizontal newfolder_body">
         <div class="control-group">
            <label class="control-label">文件夹名称：</label>
            <div class="controls">
               <input name="fname" class="fname" type="text" placeholder="10个中文字符以内">
            </div>
         </div>
         <div class="control-group" style="margin-top:20px;">
            <div class="controls">
               <span class='error server'></span>
               <input class="ppp_bluebtn submit" type="submit" value="确认"/>
            </div>
         </div>
      </div>
      </form>
   </div>
</div>

<div class="hr_resumes_match" id="shareresumedialog" style="display:none;">
   <div class="hr_resumes_matchinner">
      <div class="hr_top5match" style="width:410px;">
         <div class="hr_top5uppoint" style="right:30px;"></div>
         <div class="closediv"></div>
         <div class="sharedialogbox medium">
            <p><b>分享简历</b></p>
            <div class="sharedialog_inner"><span>分享给：</span><input type="text" class="" placeholder="请输入要分享的Email地址，多个地址用英文逗号分隔" value=""/></div>
            <div class="sharedialog_inner"><span>分享语：</span><textarea>这份简历不错，看看吧</textarea></div>
            <div class="sharedialog_inner lastbtnbox"><input type="submit" value="分享"/><a href="javascript:;">取消</a></div>
         </div>
      </div>
   </div>
</div>

<input type="hidden" name="allowZipDownload" id="allowZipDownload" value="<?php echo $_['allowZipDownload']; ?>" />
<input type="hidden" id="orderBy" value="<?php echo $_['orderBy']; ?>" />
<input type="hidden" id="orderDir" value="<?php echo $_['orderDir']; ?>" />
<input type="hidden" name="searchtoken" id="searchtoken" value="<?php echo $_['searchtoken']; ?>" />

